package com.leyou.item.service.impl;

import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import com.leyou.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 根据PID查询商品分类
 *
 * @author XiaoLuo
 * @ClassName: CategoryServiceImpl
 * @Description: ${todo}
 * @date 2019/4/13 16:18
 */
@Service public class CategoryServiceImpl implements CategoryService {
	@Autowired private CategoryMapper categoryMapper;

	@Override public List<Category> queryByParentId(Long pid) {
		Category category = new Category();
		category.setParentId(pid);

		return this.categoryMapper.select(category);
	}

	/**
	 * 根据品牌ID查询商品分类
	 * @param bid
	 * @return
	 */
	@Override public List<Category> queryByBrandId(Long bid) {

		return this.categoryMapper.queryByBrandId(bid);
	}

	/**
	 * 查询三级分类
	 * @param ids
	 * @return
	 */
	@Override public List<String> queryNamesByIds(List<Long> ids) {

		List<Category> categories = this.categoryMapper.selectByIdList(ids);
		List<String> names = new ArrayList<>();
		categories.forEach(category ->{
			names.add(category.getName());
		});
		return names;
	}

}
